﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

[AddComponentMenu("Path")]
public class Path : MonoBehaviour
{
    private Color pathColor = Color.cyan;
    private List<Vector3> nodes = new List<Vector3>();

    public bool pathVisible = true;


    public List<Vector3> Nodes
    {
        get { GetNodes(); return nodes; }
    }
    public List<Vector3> GetNodes()
    {
        nodes.Clear();
        foreach (Transform nodeChild in transform)
        {
            nodes.Add(nodeChild.transform.position);
        }

        return nodes;
    }
    void OnDrawGizmos()
    {
        if (pathVisible)
        {
            GetNodes();
            if (nodes.Count > 0)
            {
                pathColor = Color.blue;
                iTween.DrawPath(nodes.ToArray(), pathColor);
            }
        }
    }
    void OnDrawGizmosSelected()
    {
        if (pathVisible)
        {
            GetNodes();
            if (nodes.Count > 0)
            {
                pathColor = Color.red;
                iTween.DrawPath(nodes.ToArray(), pathColor);
            }
        }
    }
}
